﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using xpds_ProductMonitor.DAL;
using xpds_ProductMonitor.Models;

namespace xpds_ProductMonitor.BLL
{
    public class StuffService
    {
        private SqlServerAccess sqlServer;


        public StuffService()
        {
            if (sqlServer==null)
            {
                sqlServer = new SqlServerAccess();
            }
        }

        public DataResult<List<StuffOutWorkModel>> getList()
        {
            DataResult<List<StuffOutWorkModel>> result = new DataResult<List<StuffOutWorkModel>>();
            DataTable table = sqlServer.GetStuffData();
            List<StuffOutWorkModel> workList = new List<StuffOutWorkModel>();
            foreach (var dataRow in table.AsEnumerable())
            {
                StuffOutWorkModel model = new StuffOutWorkModel();
                model.StuffName = dataRow.Field<string>("stuff_name");
                model.OutWorkCount = dataRow.Field<int>("outwork_count");
                model.Position = dataRow.Field<string>("position");
                workList.Add(model);
            }
            if (workList!=null && workList.Count>0)
            {
                result.Data = workList;
                result.State = true;
            }
            return result;
        }
    }
}
